import com.sun.source.tree.BreakTree;

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class test {
    public static void main(String[] args) {
        int[] array={1,2,3,4,5,6};
        for (int i = 0; i <array.length ; i++) {
            System.out.print(array[i]+" ");
        }
        System.out.println();
        System.out.println("------------");
        //for each循环
        for (int x:array) {
            System.out.print(x+" ");
        }
        System.out.println();
        System.out.println("------------");
        String ret= Arrays.toString(array);
        System.out.println(ret);//打印字符串
    }
    public static void main10(String[] args) {
        int[] array={1,2,3};
        System.out.println(array[15]);
        //报错: Index 15 out of bounds for length 3 at test.main(test.java:9)
    }
    public static void main09(String[] args) {
        int[] arr={1,2,3,4,5,6};
        int[] arr2=new int[]{1,2,3,4,5,6};
        int[] arr3=new int[10];
    }
    public static int fib(int n){
        if (n==1 || n==2){
            return 1;
        }
        return fib(n-1)+fib(n-2);
    }
    public static int fib2(int n){
        int f1=1;
        int f2=1;
        int f3=0;
        for (int i = 3; i <=n ; i++) {
            f3=f1+f2;
            f1=f2;
            f2=f3;
        }
        return f3;
    }

    public static void main08(String[] args) {
        System.out.println(fib(5));
    }
    public static int sum2(int n){ //数字123求和为6
        if (n<10){
            return n;
        }
        return n%10+sum2(n/10);
    }

    public static void main07(String[] args) {
        System.out.println(sum2(123));
    }
    public static int sum(int n){ //递归求和
        if (n==1)return n;
        return n+sum(n-1);
    }

    public static void main06(String[] args) {
        System.out.println(sum(10));
    }
    public static void print(int n){  //用顺序打印数字
        if (n<10){
            System.out.println(n);
            return;
        }
        print(n/10);
        System.out.println(n%10);
    }

    public static void main05(String[] args) {
        print(123);
    }
    public static int fac(int n){ //递归阶乘
        if (n==1) return 1;
        return n*fac(n-1);
    }
    public static void main04 (String[] args) {
        System.out.println(fac(5));
    }
    public static double add(double a,double b){
        return a+b;
    }
    public static int add(int a,int b){
        return a+b;
    }

    public static void main03(String[] args) {
        add(1,2); //方法的重载
    }
    public static void main02(String[] args) {
        boolean ret=isLeapyear(2000); //实参
        if (ret==true){
            System.out.println("是闰年");
        }else{
            System.out.println("不是闰年");
        }
    }
    public  static boolean isLeapyear(int year){ //形参
        System.out.println("方法被调用了");
        if ((year%4==0&&year%100!=0)||year%400==0 ){
            return true;
        }else{
            return false;
        }
    }
    public static void main01(String[] args) {
        Random random=new Random();
        int randNum=random.nextInt(100);
        System.out.println(randNum);
        Scanner scanner=new Scanner(System.in);
        while (true){
            System.out.println("请输入数字:");
            int num=scanner.nextInt();
            if (num<randNum){
                System.out.println("小了");
            } else if (num==randNum) {
                System.out.println("恭喜你猜对了");
                break;
            }else{
                System.out.println("大了");
            }
        }
    }
}
